﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.Text;
using System.Windows.Forms;

namespace WindowsServiceHostedClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var binding = new BasicHttpBinding();
            binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

            var endpoint = new EndpointAddress("http://localhost:8000/ServiceModelSamples/service/windows");

            var calService = new CalculatorService.CalculatorClient(binding, endpoint);
            calService.ClientCredentials.Windows.ClientCredential = new NetworkCredential("hai2", "H@i1234");

            var result = calService.Add(1, 2);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var binding = new BasicHttpBinding();
            binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            var endpoint = new EndpointAddress("http://haitb-laptop:8000/ServiceModelSamples/service/basic");

            var calService = new CalculatorService.CalculatorClient(binding, endpoint);
            calService.ClientCredentials.UserName.UserName = "hai";
            calService.ClientCredentials.UserName.Password = "H@i1234";

            var result = calService.Add(1, 2);
        }
    }
}
